// pages/index/index.js

Page({
  data:{
    indicatorDots:false,
    autoplay:true,
    interval: 5000,
    duration:500,
    imgUrls: ["../../image/sch1.jpg", "../../image/sch2.jpg"],
    locationIcon:"../../image/location.png",
    
  },
  globalData:{
    searchText: ''
  },
   //分享功能
   onShareAppMessage:function(){
    return {
      title: '油菜花',
      desc: '油菜花',
      path: '/page/common/test'
    }
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    wx.hideShareMenu();
  },

  onReady:function(){
    // 页面渲染完成
   
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  openSchoolListWindow:function(){
    wx.navigateTo({
      url: '/page/school/list?categoryId=1'
    })
  },
  openMajarTypeWindow: function () {
    wx.navigateTo({
      url: '/page/majar/majar_type'
    })
  },

  openMajarSchoolListWindow: function (e) {
    
    wx.navigateTo({
      url: '/page/majar/majar_school_list?majorId=' + e.currentTarget.dataset.majorid
    })
  }, 
  openSchoolHomeWindow:function(e){
    wx.navigateTo({
      url: '/page/school/detail?schoolid=' + e.currentTarget.dataset.schoolid
    })
  },
  formSubmit:function(e){
    var self = this;
    //console.log(e.detail);
    //console.log(e.detail.value.searchText);
    var searchText = e.detail.value.searchText;
    console.log(typeof searchText);
    searchText= searchText.replace(/^\s+|\s+$/g, '');
    
    wx.request({
      url: getApp().globalData.server + "/major/search.do",
      method:"POST",
      data: '{"searchText": \"' + searchText+'","pageNum":1,"pageSize":20}',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (res.data.status != 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else if (res.data.data.list.length==0){
          wx.showToast({
            title: '无符合条件数据',
            icon: 'none', 
            duration: 1000,
            mask: true
          })
         
        }else{
          //console.log(requestObj);
          console.log(res.data);
          self.setData({
            popList: res.data.data.list
          });
        }
      },
      fail: function () {
        wx.showToast({
          title: "查询失败",
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
    })
  }
})